Skip to content

fix(linter): detect root lint target added in same generator run#35296

Merged
FrozenPandaz merged 1 commit intomasterfrom
nxc-3976
Apr 27, 2026
Merged

fix(linter): detect root lint target added in same generator run#35296
FrozenPandaz merged 1 commit intomasterfrom
nxc-3976

Conversation

@leosvelperez
Copy link
Copy Markdown
Member

Current Behavior

When a generator adds a lint target to the root project and then creates a new non-root project in the same run, the root eslint config is not split into a base config on that run. Subsequent projects created afterwards (in the same run or in separate runs) end up wired incorrectly, and users have to re-run the generator to get the migration to actually happen.

Expected Behavior

The root eslint config is split into a base config on the first run where a non-root project is created alongside a root lint target, so projects are wired correctly without requiring a second invocation.

Implementation Notes

isMigrationToMonorepoNeeded previously relied on createProjectGraphAsync() to detect the root lint target. The project graph reflects the filesystem at its last rebuild and misses targets written to the tree earlier in the same generator run.

The check now reads the tree first via getProjects(tree). The project graph is only consulted as a fallback when @nx/eslint/plugin is registered, since plugin-inferred targets do not appear on the tree — preserving the behavior introduced in #23147.

Known gaps (not addressed)

The symmetric in-flight cases on the inferred branch remain open:

  • a root eslint config file written during the same generator run with @nx/eslint/plugin already registered, and
  • @nx/eslint/plugin registered in nx.json during the same run with a root config already on disk.

Closing them would require reimplementing @nx/eslint/plugin's createNodes pipeline against the tree — the maintenance burden #23147 explicitly avoided. No known user report exercises those paths today.

Related Issue(s)

Fixes #34531

When generating a new non-root project, isMigrationToMonorepoNeeded relied on
the project graph to decide whether to split the root eslint config into a
base config. The graph reflects the filesystem, so it missed root lint
targets written to the tree earlier in the same generator run, deferring the
split to a second invocation.

Check the tree first for an explicit root lint target. Only consult the
graph (which encodes plugin-inferred targets) when @nx/eslint/plugin is
registered and the tree did not resolve the question.
@leosvelperez leosvelperez requested a review from a team as a code owner April 15, 2026 09:13
@leosvelperez leosvelperez requested a review from MaxKless April 15, 2026 09:13
@leosvelperez leosvelperez self-assigned this Apr 15, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 15, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit ec74533
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69df56c3da4cfd0008c7d089
😎 Deploy Preview https://deploy-preview-35296--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 15, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit ec74533
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69df56c39eb4050008178651
😎 Deploy Preview https://deploy-preview-35296--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Apr 15, 2026

View your CI Pipeline Execution ↗ for commit ec74533

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 49m 16s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 17s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 24s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 15s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-15 10:07:23 UTC

@FrozenPandaz FrozenPandaz merged commit 3480ef8 into master Apr 27, 2026
23 checks passed
@FrozenPandaz FrozenPandaz deleted the nxc-3976 branch April 27, 2026 04:51
ShwethaSundar pushed a commit to ShwethaSundar/nx that referenced this pull request Apr 27, 2026
…l#35296)

## Current Behavior

When a generator adds a lint target to the root project and then creates
a new non-root project in the same run, the root eslint config is not
split into a base config on that run. Subsequent projects created
afterwards (in the same run or in separate runs) end up wired
incorrectly, and users have to re-run the generator to get the migration
to actually happen.

## Expected Behavior

The root eslint config is split into a base config on the first run
where a non-root project is created alongside a root lint target, so
projects are wired correctly without requiring a second invocation.

## Implementation Notes

`isMigrationToMonorepoNeeded` previously relied on
`createProjectGraphAsync()` to detect the root lint target. The project
graph reflects the filesystem at its last rebuild and misses targets
written to the tree earlier in the same generator run.

The check now reads the tree first via `getProjects(tree)`. The project
graph is only consulted as a fallback when `@nx/eslint/plugin` is
registered, since plugin-inferred targets do not appear on the tree —
preserving the behavior introduced in nrwl#23147.

### Known gaps (not addressed)

The symmetric in-flight cases on the inferred branch remain open:

- a root eslint config file written during the same generator run with
`@nx/eslint/plugin` already registered, and
- `@nx/eslint/plugin` registered in `nx.json` during the same run with a
root config already on disk.

Closing them would require reimplementing `@nx/eslint/plugin`'s
`createNodes` pipeline against the tree — the maintenance burden nrwl#23147
explicitly avoided. No known user report exercises those paths today.

## Related Issue(s)

Fixes nrwl#34531
FrozenPandaz pushed a commit that referenced this pull request Apr 28, 2026
)

## Current Behavior

When a generator adds a lint target to the root project and then creates
a new non-root project in the same run, the root eslint config is not
split into a base config on that run. Subsequent projects created
afterwards (in the same run or in separate runs) end up wired
incorrectly, and users have to re-run the generator to get the migration
to actually happen.

## Expected Behavior

The root eslint config is split into a base config on the first run
where a non-root project is created alongside a root lint target, so
projects are wired correctly without requiring a second invocation.

## Implementation Notes

`isMigrationToMonorepoNeeded` previously relied on
`createProjectGraphAsync()` to detect the root lint target. The project
graph reflects the filesystem at its last rebuild and misses targets
written to the tree earlier in the same generator run.

The check now reads the tree first via `getProjects(tree)`. The project
graph is only consulted as a fallback when `@nx/eslint/plugin` is
registered, since plugin-inferred targets do not appear on the tree —
preserving the behavior introduced in #23147.

### Known gaps (not addressed)

The symmetric in-flight cases on the inferred branch remain open:

- a root eslint config file written during the same generator run with
`@nx/eslint/plugin` already registered, and
- `@nx/eslint/plugin` registered in `nx.json` during the same run with a
root config already on disk.

Closing them would require reimplementing `@nx/eslint/plugin`'s
`createNodes` pipeline against the tree — the maintenance burden #23147
explicitly avoided. No known user report exercises those paths today.

## Related Issue(s)

Fixes #34531
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 3, 2026

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

isMigrationToMonorepoNeeded uses graph and not getProjects

2 participants